package com.tiger.cloud.service.crm;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.tiger.cloud.common.view.SpringUtils;
import com.tiger.cloud.model.crm.PointRule;
import com.tiger.cloud.util.StringUtil;

/**
 * 积分角色
 */
public class CommonPointRule {

	private volatile static Map<String, PointRule> pointRules = new HashMap<String, PointRule>();

	/**
	 * 初始化加载积分角色
	 */
	public static void init() {
		IPointRuleService pointRuleService = SpringUtils.getBean(IPointRuleService.class);
		Map<String, Object> maps = new HashMap<String, Object>();
		List<PointRule> pointRules_ = pointRuleService.find(maps);
		for (PointRule pointRule : pointRules_) {
			pointRules.put(pointRule.getPointCode(), pointRule);
		}
	}

	/**
	 * 通过字典获取值
	 */
	public static Integer getPoint(String pointCode) {
		if (StringUtil.isEmpty(pointCode)) {
			throw new IllegalArgumentException("参数错误！");
		}
		PointRule pointRule= pointRules.get(pointCode);
		if(pointRule!=null){
			return pointRule.getPoint();
		}
		return 0;
	}

}
